// *创建自定义对象
let p1 = {};
// 动态给对象添加属性和方法
p1.name = "张三";
p1.age = 15;
p1.run = function () {
  // this访问当前对象
  console.log(this.name + ": " + this.age);
};
p1.run();

// *实例化一个自带属性和方法的对象
let p2 = {
  name: "Lisi",
  age: 20,
  run: function () {
    console.log(this.name + ": " + this.age);
  },
};
p2.run();

// *通过对象封装一个商品的信息
let product = { title: "手机", price: 3000, num: 100 };
// *通过数组封装对象的形式，封装多个商品的信息
let arr = [
  { title: "手机", price: 3000, num: 100 },
  { title: "电视", price: 2000, num: 200 },
];
let table = document.querySelector("table");

// 遍历数组
for (let p of arr) {
  let tr = document.createElement("tr");
  let titleTd = document.createElement("td");
  let priceTd = document.createElement("td");
  let numTd = document.createElement("td");
  titleTd.innerText = p.title;
  priceTd.innerText = p.price;
  numTd.innerText = p.num;
  tr.append(titleTd, priceTd, numTd);
  table.append(tr);
}
